﻿using System.Collections.Generic;
using System.Windows.Controls;
using WPFTestSolution.Bean;

namespace WPFTestSolution.Pages.Controls.ItemsControls.Selectors {
    
    /**
     * https://www.bilibili.com/video/BV1bV411A7Eq?p=56
     * 056-ComboBox下拉框控件(: Selector)
     * https://www.wpfsoft.com/2023/09/06/1880.html
     */
    public partial class _56_ComboBox_Page : Page {
        public _56_ComboBox_Page() {
            InitializeComponent();
            this.Title = "056-ComboBox下拉框控件(: Selector)";
            
            List<Person> list = new List<Person> {
                new Person { Name = "张三", Age = 22, Address = "广东省廉江市车板镇大坝村" },
                new Person { Name = "李四", Age = 23, Address = "江西省景德镇市市辖区" },
                new Person { Name = "王五", Age = 24, Address = "上海市虹口区" }
            };
            this.combobox2.ItemsSource = list;
        }

        private void combobox1_TextChanged(object sender, TextChangedEventArgs e) {
            _TextBlockTel.Text = combobox1.Text;
        }

        private void combobox2_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            if (!(sender is ComboBox combobox)) return;

            if (!(combobox.SelectedItem is Person person)) return;
 
            _TextBlockName.Text = person.Name;
            _TextBlockAge.Text = person.Age + "岁";
            _TextBlockAddress.Text = person.Address;
        }
    }
}